<?php

namespace app\wechatapi\controller\user;

use app\Request;
use think\facade\Db;
use think\facade\Env;
use think\response\Json;
use app\services\user\UserServices;
use crmeb\exceptions\AdminException;
use app\wechatapi\controller\RestBaseController;
use think\db\exception\{DataNotFoundException, DbException, ModelNotFoundException};

/**
 * 用户个人信息
 * Class AdController
 * @package app\wechatapi\controller\user
 */
class UserInfoController extends RestBaseController
{
    /** @var UserServices */
    protected $services;

    /**
     * @return void
     */
    protected function initialize()
    {
        parent::initialize();
        $this->services = app()->make(UserServices::class);
    }

    /**
     * 获取个人信息
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getUserInfo(): Json
    {
        $userId = $this->getUserId();
        /** @var UserServices $userInfo */
        $userInfo = $this->services->getOne(['id' => $userId]);
        $this->success("获取个人信息成功!", [
            'user_info' => $userInfo,
        ]);
    }
}
